﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Sunboxsoft.WinForm;
using Sunboxsoft.Common;
using DevExpress.XtraEditors;
using WebRef = Sunboxsoft.ASMS.Client.Domain.WebRef;
using Service = Sunboxsoft.ASMS.Client.Domain.Service;
using LocalService = Sunboxsoft.ASMS.Client.Domain.LocalService;
using Sunboxsoft.ASMS.Client.UI.Properties;
namespace Sunboxsoft.ASMS.Client.UI.Show
{
    /// <summary>
    /// 查看车辆详细信息
    /// </summary>
    public partial class ShowAutoMobileDetailView : UserControl, IView
    {
        WebRef.VCustomer _vCustomer = null;
        WebRef.VAutomobile _vAutomobile = null;
        Promise _promise = new Promise();
        public ShowAutoMobileDetailView()
        {
            InitializeComponent();
        }
        public ShowAutoMobileDetailView(WebRef.VCustomer model, WebRef.VAutomobile vAutomobile)
            : this()
        {
            this._vCustomer = model;
            this._vAutomobile = vAutomobile;
        }

        #region IView 成员
        public void RegisterAction(ActionNodeCollection collection)
        {
            collection
                .AddAction(new ActionNode("close", Resources.isDelete, "关闭", OnBtnClose_Click));
        }
        public void Active(ViewActiveArgs args)
        {
            _promise
            .Then(() =>
             {
                 this.BeginInvoke(new Action(() =>
                 {
                     GetAutoMobile();
                     _promise.Resolve();
                 }));
             })
            .Run();
        }
        public void Resume(ViewResumeArgs args)
        {

        }
        public ViewHeader GetHeader()
        {
            return new ViewHeader("查看车辆详细信息");
        }
        #endregion

        #region Action
        /// <summary>
        /// 关闭
        /// </summary>
        private void OnBtnClose_Click(object sender, object e)
        {
            UIContext.Current.ViewManager.CloseView(false, true);
        }
        /// <summary>
        /// 获取待修改车辆信息
        /// </summary>
        private void GetAutoMobile()
        {
            if (_vCustomer != null)
            {
                this.txtCustomerID.Text = _vCustomer.Number.ToString();
                this.txtCustomerName.Text = _vCustomer.Name;
                this.txtCustomerPhone.Text = _vCustomer.Telephone;
            }
            if (_vAutomobile != null)
            {
                this.ctlEditCarOwnerName.Text = _vAutomobile.Owner;
                this.ctlEditCarOwnerTel.Text = _vAutomobile.OwnerTelephone;
                this.ctlEditCarLPN.Text = _vAutomobile.LPN;
                this.ctlEditCarVIN.Text = _vAutomobile.VIN;
                this.ctlEditEIN.Text = _vAutomobile.EIN;
                this.ctlEditEngineType.Text = _vAutomobile.EngineType;
                this.ctlEditBrand.Text = _vAutomobile.BrandName;
                this.ctlEditMaker.Text = _vAutomobile.MakerName;
                this.ctlEditSeries.Text = _vAutomobile.SeriesName;
                this.ctlEditModule.Text = _vAutomobile.ModelName;
                this.ctlEditBoughtDate.Text = _vAutomobile.BoughtDate.ToString();
                this.ctlEditCompanyName.Text = _vAutomobile.InsuranceCompanyName;
                this.ctlEditExpireDate.Text = _vAutomobile.InsuranceExpirationDate.ToString();
                this.ctlEditInsuranceNum.Text = _vAutomobile.InsuranceNumber;
                this.ctlEditNextYearDate.Text = _vAutomobile.NextAnnualSurveyDate.ToString();
            }
        }
        #endregion
    }
}
